package mythical.controller;


import dto.MethodDto;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import mythical.result.Result;
import mythical.service.MethodService;
import org.springframework.web.bind.annotation.*;
import vo.MethodVo;

import java.util.List;

@RestController
@RequestMapping("/method/")
@Slf4j
@RequiredArgsConstructor
public class MethodController {

    private final MethodService methodService;

    /**
     * 用户获得功法
     * @param methodDto
     * @return
     */
    @PostMapping("save")
    public Result save(@RequestBody MethodDto methodDto){
        //StpUtil.checkLogin();
        log.info("获得功法：{}",methodDto);
        methodService.isave(methodDto);
        return Result.success();
    }

    /**
     * 查询用户功法
     * @return
     */
    @GetMapping("list")
    public Result<List<MethodVo>> list(){
        log.info("查询用户功法：");
        List<MethodVo> methodVoList = methodService.ilist();
        return Result.success(methodVoList);
    }

    /**
     * 批量删除功法（包含单独删除）
     * @param ids
     * @return
     */
    @DeleteMapping("delete")
    public Result delete(@RequestParam List<Long> ids){
        log.info("根据id删除功法：{}", ids);
        methodService.delete(ids);
        return Result.success();
    }


}
